﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public class NewsDataModel
    {
        HomestayWebDBEntities ent = new HomestayWebDBEntities();
        public List<Store_New_GetAllNews_Result> GetNews()
        {

            List<Store_New_GetAllNews_Result> result = ent.Store_New_GetAllNews().ToList();
            return result;

        }
        public bool AddNew(News news)
        {
            try
            {
                ent.News.AddObject(news);
                ent.SaveChanges();
                return true;
            }
            catch 
            {
                return false;
            }
        }
        public News GetNewDetail(int newID)
        {
            var query = from u in ent.News
                        where u.NewID == newID && u.IsDeleted==false
                        select u;
            News  news = new News();
            if (query != null)
            {
                news = query.ToList().FirstOrDefault();
                return news;
            }
            return null;
        }
        public int DeleteNew(int newID)
        {
            return ent.ExecuteStoreCommand("update News set isDeleted ='true' where NewID = {0}", new object[] { newID });
        }
    }
}
